package com.wintrisstech.iaroc.sunspot.test;

import java.io.IOException;

import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.io.IScalarInput;
import com.sun.spot.sensorboard.peripheral.LEDColor;
import com.sun.spot.util.BootloaderListener;
import com.sun.spot.util.Utils;
import com.wintrisstech.iaroc.sunspot.XLights;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/**
 * The startApp method of this class is called by the VM to start the
 * application.
 */
public class MidletTestMaxbotixTower extends MIDlet {

    protected void startApp() throws MIDletStateChangeException {
        new BootloaderListener().start();
        XLights lights = new XLights(EDemoBoard.getInstance(), 0, 7);
        lights.setColor(LEDColor.YELLOW);
        lights.startPsilon();
        Utils.sleep(500);
        lights.setColor(LEDColor.GREEN);
        
        EDemoBoard board = EDemoBoard.getInstance();
        IScalarInput a0Pin = board.getScalarInputs()[EDemoBoard.A0];
        IScalarInput a1Pin = board.getScalarInputs()[EDemoBoard.A1];
        IScalarInput a2Pin = board.getScalarInputs()[EDemoBoard.A2];
        IScalarInput a3Pin = board.getScalarInputs()[EDemoBoard.A3];
        while (true) {
            try {
                System.out.print("a0: ");
                print(a0Pin.getValue());
                System.out.print(" a1: ");
                print(a1Pin.getValue());
                System.out.print(" a2: ");
                print(a2Pin.getValue());
                System.out.print(" a3: ");
                print(a3Pin.getValue());
                System.out.println();
                Utils.sleep(100);
            } catch (IOException e) {
                lights.setColor(LEDColor.RED);
            }
        }
//        Utils.sleep(1000);
//        lights.setColor(LEDColor.BLUE);
    }

    protected void print(int num) {
        if (num < 10) {
            System.out.print('0');
        }
        if (num < 100) {
            System.out.print('0');
        }
        System.out.print(num);
    }
    protected void pauseApp() {
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
    }
    
}
